#ifndef HTTPMGR_H
#define HTTPMGR_H

#include "singleton.h"

#include <QObject>
#include <QString>
#include <QUrl>
#include <QNetworkAccessManager>
#include <QJsonObject>
#include <QJsonDocument>

//CRTP
class HttpMgr : public QObject, public Singleton<HttpMgr>, public std::enable_shared_from_this<HttpMgr>
{
    Q_OBJECT

public:
    ~HttpMgr();

private:
    friend class Singleton<HttpMgr>;
    explicit HttpMgr();

    void PostHttpReq(QUrl url, QJsonObject json, ReqId req_id, Modules mod);

    //槽函数最好放在信号上面写，不然可能会出问题
private slots:
    void slot_http_finished(ReqId req_id, const QString & res, ErrorCodes err, Modules mod);

signals:
    void sig_http_finish(ReqId req_id, const QString & res, ErrorCodes err, Modules mod);

    void sig_reg_mod_finish(ReqId req_id, const QString & res, ErrorCodes err);

private:
    QNetworkAccessManager m_manager;
};

#endif // !HTTPMGR_H